package org.tea.springdata.mina.test;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

/**
 * 
 * @author: John zhang
 * @version: 0.1
 */
public class ObjectClientHandler extends IoHandlerAdapter {

	public void sessionOpened(IoSession session) throws Exception {
		System.out.println("server  : " + session.getRemoteAddress());
	}

	// 当一个客户端关闭时
	public void sessionClosed(IoSession session) {
		System.out.println("one server  Disconnect !");
	}

	// 当客户端发送的消息到达时:
	public void messageReceived(IoSession session, Object message) throws Exception {
		// Write the received data back to remote peer
		System.out.println("收到服务端发来的消息: " + (String) message);
		// Message b= new Message();
		// b.setStatus(1);
		// b.setType(2);
		// b.setMsgBody("test client");
		// session.write(b);
	}

	// 发送消息给客户机器
	public void messageSent(IoSession session, Object message) throws Exception {
		message = message + "asdasd";
		System.out.println("发送消息给服务端: " + message);
	}

	// 发送消息异常
	public void exceptionCaught(IoSession session, Throwable cause) {
		session.close();
	}

	// //sessiong空闲
	// public void sessionIdle( IoSession session, IdleStatus status )
	// {
	// }
	// 创建 session
	public void sessionCreated(IoSession session) {

	}
}